<template>
  <div class="app-container calendar-list-container">
    <basic-container>
      <div class="filter-container">
        <el-button-group>
          <el-button v-if="orgManager_btn_add" type="primary" icon="plus" @click="handlerAdd" label="plus">添加</el-button>
          <el-button v-if="orgManager_btn_edit" type="primary" icon="edit" @click="handlerEdit" label="edit">编辑</el-button>
          <el-button v-if="orgManager_btn_del" type="primary" icon="delete" @click="handleDelete" label="delete">删除</el-button>
          <el-button type="primary" icon="role" @click="handleisShow" label="role">角色</el-button>
        </el-button-group>
      </div>
      <el-row>
        <el-col :span="6" style="margin-top:15px;">
          <el-tree style="height: 500px;overflow-y: auto;" :data="treeData" :props="defaultProps" :filter-node-method="filterNode" class="filter-tree" type="primary"
            node-key="id" highlight-current default-expand-all @node-click="getNodeData" />
        </el-col>

        <el-col :span="18" style="margin-top: 15px;">
          <el-tabs v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="组织管理" name="first">
                <el-form class="verify-form" ref="form" :label-position="labelPosition" :rules="rules" :model="form"
                  label-width="80px" v-if="orgshow">
                  <el-form-item label="组织类型" prop="type">
                    <el-radio-group v-model="form.type">
                      <el-radio v-if="form.type == 'UNIT'" v-model="form.type" :disabled="formEdit" label="UNIT">单位</el-radio>
                      <el-radio v-if="form.type == 'DEPT'" v-model="form.type" :disabled="formEdit" label="DEPT">部门</el-radio>
                      <el-radio v-if="form.type == 'POS'" v-model="form.type" :disabled="formEdit" label="POS">岗位</el-radio>
                    </el-radio-group>
                  </el-form-item>
                  <div v-if="form.type=='UNIT' || form.type=='POS'">
                    <el-form-item label="组织名称" prop="name">
                      <el-input v-model="form.name" :disabled="formEdit==false?false:true" placeholder="请输入组织名称" />
                    </el-form-item>
                    <el-form-item label="编码" prop="code">
                      <el-input v-model="form.code" :disabled="formEdit" placeholder="请输入编号"></el-input>
                    </el-form-item>
                    <el-form-item label="编号" prop="number">
                      <el-input v-model="form.number" :disabled="formEdit" placeholder="请输入编号"></el-input>
                    </el-form-item>
                  </div>
                  <div v-if="form.type=='DEPT'">
                    <el-form-item label="父级节点" prop="parentId">
                      <el-input v-model="form.parentId" disabled placeholder="请输入父级节点" />
                    </el-form-item>
                    <el-form-item v-if="formEdit" label="节点编号" prop="number">
                      <el-input v-model="form.number" :disabled="formEdit" placeholder="节点编号" />
                    </el-form-item>
                    <el-form-item label="部门名称" prop="name">
                      <el-input v-model="form.name" :disabled="formEdit" placeholder="请输入名称" />
                    </el-form-item>
                    <el-form-item label="单位名称" prop="name">
                      <avue-select v-model="form.unitId" :dic="unitOptions" :props="unitProps" placeholder="请选择单位" />
                    </el-form-item>
                    <el-form-item label="排序" prop="sort">
                      <el-input v-model="form.sort" :disabled="formEdit" type="number" placeholder="请输入排序" />
                    </el-form-item>
                    <el-form-item label="编码" prop="code">
                      <el-input v-model="form.code" :disabled="formEdit" placeholder="请输入编号"></el-input>
                    </el-form-item>
                    <el-form-item label="编号" prop="number">
                      <el-input v-model="form.number" :disabled="formEdit" placeholder="请输入编号"></el-input>
                    </el-form-item>
                    <el-form-item label="部门类型" prop="deptType">
                      <el-select v-model="form.deptType" placeholder="请选择部门类型">
                        <el-option v-for="item in deptTypeData" :key="item.id" :label="item.deptTypeName" :value="item.id">
                        </el-option>
                      </el-select>
                    </el-form-item>
                  </div>

                  <el-form-item v-if="formStatus == 'update'">
                    <el-button type="primary" @click="update" v-prevent-re-click>更新</el-button>
                    <el-button @click="onCancel">取消</el-button>
                  </el-form-item>
                  <el-form-item v-if="formStatus == 'create'">
                    <el-button type="primary" @click="create" v-prevent-re-click>保存</el-button>
                    <el-button @click="onCancel">取消</el-button>
                  </el-form-item>
                </el-form>
                <el-form label-width="80px" ref="role" v-if="!orgshow">
                  <el-form-item label="角色" prop="roles">
                    <el-select v-model="roleValue" multiple placeholder="请选择" prop="roles" value-key="roleId" @change="roleReceiveId($event)">
                      <el-option v-for="(item,index) in rolesOptions" :key="index.id" prop="roles" :label="item.roleName"
                        :value="item.roleId"></el-option>
                    </el-select>
                  </el-form-item>
                  <el-form-item >
                    <el-button type="primary" @click="updateRoles">更新</el-button>
                    <el-button @click="onCancel">取消</el-button>
                  </el-form-item>
                </el-form>
              </el-tab-pane>
              <el-tab-pane label="用户管理" name="second">
                <!-- 查询条件 -->
                <el-form inline label-width="80px">
                  <el-form-item label="用户名">
                    <el-input v-model="searchForm.username"></el-input>
                  </el-form-item>
                  <el-form-item label="姓名">
                    <el-input v-model="searchForm.realName"></el-input>
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" icon="el-icon-search" @click="searchHandle">搜索</el-button>
                    <el-button icon="el-icon-delete" @click="clearSearchForm">清空</el-button>
                  </el-form-item>
                </el-form>
                <!-- 功能按钮 -->
                <el-row>
                  <el-col :span="12">
                    <el-button v-if="permissions.sys_user_add" type="primary" icon="el-icon-plus" @click="createOrUpdate('')">添加</el-button>
                  </el-col>
                  <el-col :span="12" style="float: right;">

                  </el-col>
                </el-row>
                <!-- 查询数据 -->
                <el-table :data="userList" border>
                  <!-- <el-table-column type="index" header-align="center" align="center" width="40" fixed="left" :index="indexMethod"></el-table-column> -->
                  <el-table-column key="1" prop="username" label="用户名" width="80" fixed="left"></el-table-column>
                  <el-table-column key="2" prop="realName" label="姓名" width="80" fixed="left"></el-table-column>
                  <el-table-column key="3" prop="deptId" label="所属主部门" width="120">
                    <template slot-scope="scope">{{deptNameConvert(scope.row.deptId)}}</template>
                  </el-table-column>
                  <el-table-column key="4" prop="hisWorkNumber" label="his系统工号" width="120"></el-table-column>
                  <el-table-column key="5" prop="phone" label="手机号" width="120"></el-table-column>
                  <el-table-column key="6" prop="unitId" label="单位" width="120">
                    <template slot-scope="scope">{{unitNameConvert(scope.row.unitId)}}</template>
                  </el-table-column>
                  <el-table-column key="7" prop="jobType" label="岗位类型" width="80">
                    <template slot-scope="scope">{{valueToName(scope.row.jobType)}}</template>
                  </el-table-column>
                  <el-table-column key="8" prop="posId" label="岗位" width="80">
                    <template slot-scope="scope">{{posNameConvert(scope.row.posId)}}</template>
                  </el-table-column>
                  <el-table-column key="9" prop="roleId" label="角色" width="80">
                    <template slot-scope="scope">{{roleNameConvert(scope.row.roleId)}}</template>
                  </el-table-column>
                  <el-table-column key="10" prop="lockFlag" label="状态" width="60">
                    <template slot-scope="scope">
                      <el-tag v-if="scope.row.lockFlag == '0'">有效</el-tag>
                      <el-tag v-if="scope.row.lockFlag == '9'" type="danger">锁定</el-tag>
                    </template>
                  </el-table-column>
                  <el-table-column key="11" prop="createTime" label="创建时间" width="150"></el-table-column>
                  <el-table-column key="12" label="操作" width="180" fixed="right">
                    <template slot-scope="scope">
                      <el-button v-if="permissions.sys_user_edit" type="text" icon="el-icon-s-home" @click="userOrgUpdate(scope.row)">组织</el-button>
                      <el-button v-if="permissions.sys_user_edit" type="text" icon="el-icon-edit" @click="createOrUpdate(scope.row.id,scope.row.roleId)">编辑</el-button>
                      <el-button v-if="permissions.sys_user_del" type="text" icon="el-icon-delete" @click="deletesUser(scope.row)">删除</el-button>
                    </template>
                  </el-table-column>
                </el-table>

                <div class="avue-crud__pagination">
                  <el-pagination
                          @size-change="sizeChangeHandle"
                          @current-change="currentChangeHandle"
                          :current-page="pageIndex"
                          :page-sizes="[10, 20, 50, 100]"
                          :page-size="pageSize"
                          :total="totalPage"
                          background
                          layout="total, sizes, prev, pager, next, jumper">
                  </el-pagination>
                </div>
              </el-tab-pane>
            </el-tabs>
        </el-col>
      </el-row>

    </basic-container>

    <!-- 弹窗， 添加-编辑 -->
    <add-update v-if="formVisible" ref="formDialog" @refreshDataList="getUserList"></add-update>
    <!-- 弹窗， 分配组织 -->
    <org-divide v-if="orgVisible" ref="orgDialog" @refreshDataList="getUserList"></org-divide>

  </div>
</template>


<script>
  import { addObj, delObj, fetchOrg, getObj, putObj, getOrgQuery, roleupdateOrg, roleorgQuery, getUserObj } from "@/api/admin/org";
  import { mapGetters } from "vuex";
  import { deptRoleList } from "@/api/admin/role";
  import { unitList } from '@/api/admin/unit'
  import {getInfoList} from '@/api/admin/jobtype'
  import { posQuery } from '@/api/admin/pos'
  import { getTreeByUint, getDeptInfo, fetchTree,getDeptTypeList } from '@/api/admin/dept'
  import { tableOption } from '@/const/crud/admin/org'
  import { delUserObj, putUserObj, addUserObj, fetchList, updateUserOrg } from '@/api/admin/user'

  import AddUpdate from './components/AddOrUpdate'
  import OrgDivide from './components/OrgDivide'

  export default {
    name: "org",
    data() {
      var validList = (rule, value, callback) => {
        if (this.validAdd == "添加") {
          this.query({
              id: this.currentId,
              type: this.form.type,
              paraType: rule.field.toUpperCase(),
              para: value
            },
            rule,
            value,
            callback
          );
        } else if (this.validedit == "编辑") {
          this.query({
              type: this.form.type,
              paraType: rule.field.toUpperCase(),
              para: value
            },
            rule,
            value,
            callback
          );
        } else if ((this.validdele = "删除")) {}
      };
      return {
        jobTypeOptions: [],
        list: [],
        activeName: 'first',
        orgData: {},
        queryCode: 1,
        parentId: null,
        formEdit: true,
        formStatus: "",
        showElement: false,
        validAdd: "",
        validedit: "",
        validdele: "",
        _name: "",
        _code: "",
        _number: "",
        orgshow: true,
        roleOrgId: null,
        roleValue: [],
        roleReceive: [],
        rolesOptions: [],
        treeDeptData: [],
        treeDeptUserData: [],
        typeOptions: ["0", "1"],
        methodOptions: ["GET", "POST", "PUT", "DELETE"],
        orgsOptions: [],
        listLoading: true,
        listQuery: {
          name: undefined
        },
        unitProps: {
          label: 'name',
          value: 'id'
        },
        posProps: {
          label: 'name',
          value: 'id'
        },
        deptProps: {
          label: 'name',
          value: 'id'
        },
        userDeptProps: {
          label: "name",
          value: "id",
          children: "children"
        },
        deptTypeData: [],
        rolelist: {
          label: "name"
        },
        role: [],
        treeData: [],
        defaultProps: {
          children: "children",
          label: "name"
        },
        checkedKeys: [],

        roleProps: {
          label: "roleName",
          value: "roleId"
        },
        idNameProps: {
          label: 'name',
          value: 'id'
        },
        unitOptions: [],
        deptOptions: [],
        posOptions: [],
        rules: {
          parentId: [{required: true,message: "请输入父级节点",trigger: "blur"}],
          relId: [{required: true,message: "请选择关联信息",trigger: "change"}],
          //id: [{ required: true, message: "请输入节点编号", trigger: "blur" }],
          name: [
            {required: true,message: "请输入部门名称",trigger: "blur"},
            {min: 1,max: 32,message: "长度在 1 到 32 个字符",trigger: "blur"},
            // { validator: validList, trigger: "blur" }
          ],
          code: [{required: true,message: "请输入编码",trigger: "blur"},
            // { validator: validList, trigger: "blur" }
          ],
          fullName: [{required: true,message: "请输入名称",trigger: "blur"}],
          number: [
            {required: true,message: "请输入编号",trigger: "blur"},
            // { validator: validList, trigger: "blur" }
          ],
          type: [{required: true,message: "请输入类型",trigger: "blur"}]
        },
        labelPosition: "right",
        form: {
          name: undefined,
          sort: undefined,
          parentId: undefined,
          id: undefined,
          relId: undefined,
          code: undefined,
          number: undefined,
          type: undefined,
          deptId: undefined,
          unitId: undefined,
          posId: undefined,
          jobType: undefined,

        },
        user: {
          username: undefined,
          realName: undefined,
          password: undefined,
          deptId: undefined,
          phone: undefined,
          unitId: undefined,
          posId: undefined
        },
        userList: [],
        pageIndex: 1,
        pageSize: 20,
        totalPage: 0,
        searchForm: {},

        rolesment: 0,
        currentId: 0,
        orgManager_btn_add: false,
        orgManager_btn_edit: false,
        orgManager_btn_del: false,
        formVisible: false,
        orgVisible: false
      };
    },
    components:{
      AddUpdate,
      OrgDivide
    },
    created() {
      this.getList()
      this.getUserList()
      this.getUnitListData();
      this.getDeptListDate();
      this.getDeptType()
      this.getDeptTree();
      this.getPosListDate();
      this.getJobTypeList();
      this.orgManager_btn_add = this.permissions["sys_org_add"];
      this.orgManager_btn_edit = this.permissions["sys_org_edit"];
      this.orgManager_btn_del = this.permissions["sys_org_del"];
    },
    computed: {
      ...mapGetters(["elements", "permissions"])
    },
    // paraType 条件类型 (CODE,NUMBER,NAME) type 组织类型 (UNIT-单位,DEPT-部门,POS-岗位,USER-人员
    // 返回0 或者1
    methods: {
      //  自定义索引值
      indexMethod(index){
        return index + 1
      },
      //  获取单位列表
      getUnitListData() {
        unitList().then(response => {
          this.unitOptions = response.data.data;
        })
      },
      //  获取部门列表
      getDeptListDate() {
        getDeptInfo().then(response => {
          this.deptOptions = response.data.data;
        })
      },
      // 获取岗位类型
      getJobTypeList(){
          getInfoList().then(result => {
              this.jobTypeOptions = result.data.data
              console.log(this.jobTypeOptions)
          })
      },
      //  获取岗位列表
      getPosListDate() {
        let params = {current:1,size:1000}
        posQuery(params).then(response => {
          this.posOptions = response.data.data.records;
        })
      },
      //  根据单位获取部门树结构
      getDeptTree() {
        getTreeByUint().then(response => {
          this.treeDeptData = response.data.data
        })
      },
      //  删除用户信息
      deletesUser(row){
        this.$confirm('此操作将永久删除该用户(用户名:' + row.username + '), 是否继续?', '提示', {confirmButtonText: '确定',cancelButtonText: '取消',type: 'warning'}).then(() => {
          delUserObj(row.id).then(() => {
              // this.list.splice(index, 1)
              this.$notify({title: '成功',message: '删除成功',type: 'success',duration: 2000})
            }).cache(() => {
              this.$notify({title: '失败',message: '删除失败',type: 'error',duration: 2000})
            })
        })
      },
      //  用户组织更新
      userOrgUpdate(row){
        this.orgVisible = true
        this.$nextTick(() => {
          this.$refs.orgDialog.init(row)
        })
      },
      //  tab切换
      handleClick(val){
        // dothing
      },
      checkDept(data, node, store) {
        this.form.relId = data.id
      },
      handleisShow() {
        this.orgshow = !this.orgshow;
      },
      roleReceiveId(event) {
        this.roleReceive = event;
      },
      query(qurey, rule, value, callback) {
        if (value == this._name || value == this._code || value == this._number) {
          callback();
        } else {
          getOrgQuery(qurey).then(res => {
            this.queryCode = JSON.stringify(res.data.data);
            let queryRule = rule.field;
            let verFicaNum = /^[0-9]*$/;
            let verFicaName = /^([A-Z\u4E00-\u9FA5])+$/i;
            let verFicaCode = /^[A-Z]*$/;
            let verFicaBlack = /^[\u4e00-\u9fa5_a-zA-Z0-9]+$/;
            if (this.queryCode == 0) {

              if (queryRule == "name") {
                if (this.queryCode == 1) {
                  callback();
                }
                callback(new Error("此用户已存在"));
              } else if (queryRule == "code") {
                if (this.queryCode == 1) {
                  callback();
                }
                callback(new Error("此编码已存在"));
              } else if (queryRule == "number") {
                if (this.queryCode == 1) {
                  callback();
                }
                callback(new Error("此编号已存在"));
              }
            } else if (this.queryCode == 1) {
              if (queryRule == "name") {
                if (!verFicaName.test(value)) {
                  callback(new Error("输入汉字或字符"));
                }
              } else if (queryRule == "code") {
                if (!verFicaCode.test(value))
                  callback(new Error("只能输入大写字符"));
                if (!verFicaBlack) {
                  callback(new Error("不能包含空格以及特殊字符"));
                }
              } else if (queryRule == "number") {
                if (!verFicaNum.test(value))
                  callback(new Error("输入值必须为数字"));
                if (!verFicaBlack.test(value)) {
                  callback(new Error("不能包含空格以及特殊字符"));
                }
              }
              callback();
            }
          });
        }
      },
      //  获取组织列表
      getList() {
        fetchOrg(this.listQuery).then(response => {
          this.treeData = response.data.data;
        });
        deptRoleList().then(response => {
          this.rolesOptions = response.data.data;
        });
      },
      //  获取用户列表
      getUserList(page, params) {
        this.listLoading = true
        fetchList(Object.assign({current: this.pageIndex,size: this.pageSize}, this.getUserData, this.searchForm)).then(response => {
          this.userList = response.data.data.records
          this.totalPage = response.data.data.total
          this.listLoading = false;
        })
      },
      //  搜索查询用户
      searchHandle(){
        this.pageIndex = 1
        this.getUserList()
      },
      //  清空搜索条件
      clearSearchForm(){
        for(let key in this.searchForm){
          this.searchForm[key] = ''
        }
      },
      //  每页条数发生改变事件
      sizeChangeHandle(val){
        this.pageSize = val
        this.pageIndex = 1
        this.getUserList()
      },
      //  当前页数变化事件
      currentChangeHandle(val){
        this.pageIndex = val
        this.getUserList()
      },
      handleUpdate(row, index) {
        this.$refs.crud.rowEdit(row, index)
        this.form.password = undefined
      },
      // handleFilter(param) {
      //   this.searchForm = param
      //   this.getUserList(this.page, param)
      // },
      // handleRefreshChange() {
      //   this.getUserList(this.page)
      // },
      createOrUpdate(id,roleId) {
        this.formVisible = true

        let orgData = {}
        if(!id){
          orgData = this.orgData
        }

        this.$nextTick(() => {
          this.$refs.formDialog.init(id,orgData,roleId)
        })
      },
      handleDept() {
        fetchTree().then(response => {
          this.treeDeptUserData = response.data.data
        })
      },
      getPosListData() {
        let params = {current: 1,size: 100}
        posQuery(params).then(result => {
          this.posOptions = result.data.data.records
        })
      },
      filterNode(value, data) {
        if (!value) return true;
        return data.label.indexOf(value) !== -1;
      },
      getNodeData(data) {

        if (!this.formEdit) {
          this.formStatus = "update";
        }
        this.roleOrgId = data.id
        getObj(data.id).then(response => {
          this.form = response.data.data;
          console.log(this.form)
          this.form.deptId = (this.form.relId) ? this.form.relId.toString() : ''
          this.parentId = response.data.data.parentId;
          this._name = response.data.data.name;
          this._number = response.data.data.number;
          this._code = response.data.data.code;
          data.extend = this.form.type
          data.orgName = this.form.name

          let getUserData = JSON.parse(JSON.stringify(data))
          this.getUserData = getUserData
          delete getUserData.children

          this.orgData = data

          console.log(data)

          this.getUserList({
            current: 1,
            size: 20
          }, getUserData)
        });
        roleorgQuery(data.id).then(response => {
          let roleIdarr = [];
          for (let i = 0; i < response.data.data.length; i++) {
            roleIdarr[i] = response.data.data[i].roleId;
          }
          this.roleValue = roleIdarr;
        })
        getUserObj(data.id).then(response => {
          this.user = response.data.data || {};
        })

        this.currentId = data.id;
        this.showElement = true;
      },
      getOrgData() {
        fetchOrg().then(response => {
          this.orgsOptions = response.data.data;
        })
        this.getRoleListData()
      },
      getRoleListData() {
        deptRoleList().then(response => {
          this.rolesOptions = response.data.data
        })
      },
      handlerEdit(value) {
        this.orgshow = true;
        this.validedit = value.target.innerText;
        if (this.form.id) {
          this.formEdit = false;
          this.formStatus = "update";
        }
      },
      handlerAdd(value) {
        if (this.form.type == 'POS') {
          alert("请选择部门添加");
        } else {
          let str = this.form.type;
          this.orgshow = true;
          this.validAdd = value.target.innerText;
          this.resetForm(str);
          if (this.parentId == 0) {
            this.form.type = 'UNIT'
          } else if (this.form.type == 'UNIT') {
            this.form.type = 'DEPT'
          } else if (this.form.type == 'DEPT') {
            this.form.type = 'POS'
          }
          this.formEdit = false;
          this.formStatus = "create";
        }

      },
      handleDelete(value) {
        this.orgshow = true;
        this.validdele = value.target.innerText;
        this.$confirm("此操作将永久删除, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          delObj(this.currentId).then(() => {
            this.getList();
            this.resetForm();
            if (this.parentId == 0) {
              this.form.type = 'UNIT'
            } else {
              this.form.type = 'DEPT'
            }
            this.onCancel();
            this.$notify({
              title: "成功",
              message: "删除成功",
              type: "success",
              duration: 2000
            });
          });
        });
      },
      update() {
        this.$refs.form.validate(valid => {
          if (!valid) return;
          this.form.user = this.user
            console.log(this.user)
          if (this.form.type == "USER") {
            this.form.name = this.user.realName;
            this.form.code = this.user.username;
            this.form.number = this.user.username;
          }
          putObj(this.form).then(() => {
            this.getList();
            this.$notify({
              title: "成功",
              message: "更新成功",
              type: "success",
              duration: 2000
            });
          });
        });
      },
      create() {
        this.$refs.form.validate(valid => {
          addObj(this.form).then(() => {
            this.getList();
            this.$notify({
              title: "成功",
              message: "创建成功",
              type: "success",
              duration: 2000
            });
          });
        });
      },
      updateRoles() {
        roleupdateOrg({
          orgId: this.roleOrgId,
          roles: this.roleReceive
        }).then(() => {
          this.$notify({
            title: "成功",
            message: "角色更新成功",
            type: "success",
            duration: 2000
          })
        })

      },
      onCancel() {
        this.orgshow = true;
        this.formEdit = true;
        this.formStatus = "";
      },
      resetForm(str) {
        this.form = {
          parentId: this.currentId,
          name: undefined,
          sort: undefined,
          id: undefined,
          relId: undefined,
          code: undefined,
          number: undefined,
          type: str,
          deptId: undefined,
          unitId: undefined
        };
        this.user = {
          username: undefined,
          realName: undefined,
          password: undefined,
          deptId: undefined,
          phone: undefined,
          unitId: undefined,
          posId: undefined
        };
      },

      //  部门格式转换
      deptNameConvert(code){
        let obj = {}
        obj = this.deptOptions.find(item => {
          if(item.id == code) return item
        })
        if(obj && obj.name) return obj.name
      },
      //  单位格式转换
      unitNameConvert(code){
        let obj = {}
        obj = this.unitOptions.find(item => {
          if(item.id == code) return item
        })
        if(obj && obj.name) return obj.name
      },
        //岗位类型格式转化
      valueToName(code){
          let obj = {}
          let str = '';
          if(code){
              let codeLst = code.split(",");
              for(let i = 0; i<codeLst.length; i++){
                  obj = this.jobTypeOptions.forEach((item,index) => {
                      if(item.id == codeLst[i]){
                          if(i != codeLst.length - 1){
                              str += item.jobName +  "," ;
                          }else{
                              str += item.jobName;
                          }
                      }
                  })
              }
              return str
          }

      },
      //  岗位格式转换
      posNameConvert(code){
        let obj = {}
        obj = this.posOptions.find(item => {
          if(item.id == code) return item
        })
        if(obj && obj.name) return obj.name
      },
      //  角色格式转换
      roleNameConvert(code){
          let obj = {}
          let str = '';
          if(code){
            let codeLst = code.split(",");
            for(let i = 0; i<codeLst.length; i++){
                obj = this.rolesOptions.forEach((item,index) => {
                    if(item.roleId == codeLst[i]){
                        if(i != codeLst.length - 1){
                            str += item.roleName +  "," ;
                        }else{
                            str += item.roleName;
                        }
                    }
                })
            }
            return str
          }

      },
      //获取部门类型
    getDeptType(){
      getDeptTypeList().then(result => {
        this.deptTypeData = result.data.data
      })
    }
    }
  };
</script>

<style scoped>
  .el-select {
    display: flex;
  }
</style>
